package edu.ccut.saturn.studio.dialog.attributevalueassignmentdialog;

import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.TableItem;

import edu.ccut.saturn.studio.logic.model.saturn.SaturnDbDataElement;

public class MyCellModifierLittleParameter implements ICellModifier {
	private TableViewer tableViewer;
	
	public MyCellModifierLittleParameter(TableViewer tableViewer){
		this.tableViewer = tableViewer;
	}

	public boolean canModify(Object element, String property) {
		return true;
	}

	public Object getValue(Object element, String property) {
		SaturnDbDataElement o = (SaturnDbDataElement) element;
		if (property.equals("name")){
			return o.getName();
		} else if(property.equals("value")){
			return o.getNamevalue();
		}
		throw new RuntimeException("" + property); 
	}
	
	public void modify(Object element, String property, Object value) {
		TableItem item = (TableItem) element;
		SaturnDbDataElement o = (SaturnDbDataElement) item.getData();
		if (property.equals("value")) {
			String newValue = (String) value;
			o.setNamevalue(newValue);
		}  else {
			throw new RuntimeException("" + property); 
		}
		tableViewer.update(o, null);
	}
}